<?php 
	$table = $this->table;
	$data_count = $table->getData_count();
	$page = $table->getPage();
	$line_per_page = $table->getLine_per_page();
	$search_link = $table->getSearch_link();
	$delete_link = $table->getDelete_link();
	
	$page_count = ceil($data_count / $line_per_page);
	$display_page = 5;
	
	$display_pages = array();
	
	$display_mode = 0;
	//process paging		
	if($page == 1){
		for($i=1; $i <= $display_page && $i <= $page_count; $i++)
			$display_pages[] = $i;
		$display_mode = 1;
		
	}else if($page == $page_count){
		for($i = $page_count,$k=0; $i > 0 && $k < 5; $i--,$k++)
			$display_pages[] = $i;
		$display_pages = array_reverse($display_pages);
		$display_mode = 2;
		
	}else{
		if($page < ceil($display_page / 2)){
			$min_page = 1;
			$max_page = $page_count < $display_page ? $page_count : $display_page;
			
		}else if($page > $page_count - floor($display_page/2) && $page < $page_count){
			$max_page = $page_count;
			$min_page = $page_count - $display_page > 0 ? $page_count - $display_page + 1 : 1;
			 
		}else{
			$min_page = $page - floor($display_page/2);
			$max_page = $page + floor($display_page/2);
		}
		
		for($i = $min_page; $i <= $max_page; $i++){
			$display_pages[] = $i;
		}
	}
?>

<div class="block-controls" style="margin-bottom: 0px">

	<?php if($data_count > 0):?>
	<ul class="controls-buttons">
		<?php if($display_mode == 2 || $display_mode == 0):?>
			<li>
				<a href="" onclick="doChangePage(1);return false">
					<?php echo $this->translate('最初')?>
				</a>
			</li>

			<li>
				<a href="" onclick="doChangePage(<?php echo $page - 1 > 0 ? $page - 1 : $page?>);return false;">
					<img src="/images/icons/fugue/navigation-180.png" width="16" height="16">
					<?php echo $this->translate('前')?>
				</a>
			</li>	
		<?php endif;?>
		
		<?php foreach($display_pages as $item):?>
			<li>
				<a href="" onclick="doChangePage(<?php echo $item?>);return false;" <?php echo $page == $item ? "class='current'" : ""?>>
					<?php echo $item?>
				</a>
			</li>	
		<?php endforeach;?>
		
		<?php if($display_mode < 2):?>
			<li>
				<a href="" onclick="doChangePage(<?php echo $page + 1 > $page_count ? $page : $page + 1?>);return false;">
					<?php echo $this->translate('次')?>
					<img src="/images/icons/fugue/navigation.png" width="16" height="16">
				</a>
			</li>
			
			<li>
				<a href="" onclick="doChangePage(<?php echo $page_count?>);return false;">
					<?php echo $this->translate('最後')?>
				</a>
			</li>	
		<?php endif;?>
		
		<li class="sep"></li>
		<li><a href="#" onclick="refreshTable();return false;"><img src="/images/icons/fugue/arrow-circle.png" width="16" height="16"></a></li>
	</ul>
	<?php endif;?>
</div>
<?php echo $this->formHidden("page", $page)?>
<?php echo $this->formHidden("refresh_url", $search_link)?>
<?php echo $this->formHidden("delete_link", $delete_link)?>